package org.chaiyi.template.core.register.contractor.bean.process;

import org.chaiyi.template.core.common.common.BeanNameManage;
import org.chaiyi.template.core.common.contract.ContractInfo;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;

/**
 * @author Gong.Yang
 */
public class ContractInfoRegister implements IServiceProcess {
    @Override
    public void register(ContractInfo<?, ?> contractInfo, BeanDefinitionRegistry beanDefinitionRegistry) {
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(ContractInfo.class)
                .addConstructorArgValue(contractInfo.getPath())
                .addConstructorArgValue(contractInfo.getName())
                .addConstructorArgValue(contractInfo.getSupporter())
                .addConstructorArgValue(contractInfo.getEntity())
                .addConstructorArgValue(contractInfo.getIService())
                .getBeanDefinition();
        String beanName = BeanNameManage.getContractInfoName(contractInfo.getIService());
        beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition);
    }
}
